package cn.myframe.service.sys.impl;

import cn.myframe.dao.sys.SysUserRoleDao;
import cn.myframe.entity.sys.SysUserRoleEntity;
import cn.myframe.service.BaseServiceImpl;
import cn.myframe.service.sys.SysUserRoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hhq
 * @version 创建时间：2018年08月27日
 * @email hhq@myframe.cn
 */
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRoleDao,SysUserRoleEntity> implements SysUserRoleService {
	@Autowired
	private SysUserRoleDao sysUserRoleDao;
	
	@Override
    public List<Long> selectUserRoleIds(Long userId) {
        return baseMapper.selectUserRoleIds(userId);
    }

	@Override
	public void saveOrUpdate(Long userId, List<Long> roleIdList) {
		if(roleIdList.size() == 0){
			return ;
		}
		
		//先删除用户与角色关系
		sysUserRoleDao.delete(userId);
		
		//保存用户与角色关系
		Map<String, Object> map = new HashMap<>();
		map.put("userId", userId);
		map.put("roleIdList", roleIdList);
		sysUserRoleDao.save(map);
		
	}
}
